package cn.openea.perpartner.meily.web.controller;


import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.meily.web.entity.TaskHall;
import cn.openea.perpartner.meily.web.entity.dto.SearchDto;
import cn.openea.perpartner.meily.web.entity.vo.TaskHallVo;
import cn.openea.perpartner.meily.web.service.ITaskHallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (MerryTaskHall)表控制层
 *
 * @author Weird077
 * @since 2022-12-01 18:22:43
 */
@Api(tags = "任务大厅")
@RestController
@RequestMapping("/hall")
public class TaskHallController extends BaseController {

    @Resource
    private ITaskHallService hallService;

    @ApiOperation(value = "分页查询")
    @PostMapping("/list")
    public TableDataInfo selectList(@RequestBody SearchDto dto) {
        startPage();
        List<TaskHall> list = hallService.selectList(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "首页数据")
    @PostMapping("/index/list")
    public TableDataInfo selectIndexList(@RequestBody SearchDto dto) {
        List<TaskHall> list = hallService.selectIndexList(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "查询数据")
    @GetMapping("{id}")
    public AjaxResult selectOne(@PathVariable Serializable id) {
        return success(this.hallService.getById(id));
    }

    @ApiOperation(value = "保存数据")
    @PostMapping("/save")
    public AjaxResult insert(@RequestBody TaskHall hall) {

        return toAjax(this.hallService.insert(hall));
    }

    @ApiOperation(value = "更新数据")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody TaskHall hall) {

        return toAjax(this.hallService.edit(hall));
    }

    @ApiOperation(value = "删除数据")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestParam("idList") List<Long> idList) {
        return toAjax(this.hallService.removeByIds(idList));
    }

    @ApiOperation(value = "热门任务")
    @PostMapping("/hot/task")
    public AjaxResult getHotTask(@RequestBody SearchDto dto) {
        String result = this.hallService.getHotTask(dto).getTaskName();
        return AjaxResult.success("操作成功！", result);
    }

    @ApiOperation(value = "批量下架任务")
    @PostMapping("/batch/offShelf")
    public AjaxResult offShelf(@RequestBody TaskHallVo vo) {
        return toAjax(this.hallService.offShelf(vo));
    }
}

